<template>
  <el-pagination
    class="pagination"
    :layout="layout"
    :total="total"
    :current-page.sync="currentPage"
    :page-sizes="[10,12, 20, 30, 48, 100]"
    :page-size="pageSize"
    @size-change="sizeChange"
    @current-change="pageChange"
  />
</template>

<script>
export default {
  props: {
    total: {
      type: Number,
      default: 0
    },
    page: {
      type: Number,
      default: 1
    },
    limit: {
      type: Number,
      default: 10
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next'
    }
  },
  data() {
    return {}
  },
  computed: {
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    pageSize: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    }
  },
  methods: {
    sizeChange(num) {
      window.scrollTo({
        top: 0,
        behavior: 'smooth'
      })
      this.$emit('changePage', 1, num)
    },
    pageChange(page) {
      window.scrollTo({
        top: 0,
        behavior: 'smooth'
      })
      this.$emit('changePage', page, this.pageSize)
    }
  }
}
</script>

<style lang="scss" scoped>
.pagination {
  padding: 20px 0;
}
</style>
